home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk13 / makeml / makeml.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  6KB  |  190 lines

  1. /* DSKINFO
  2.  *
  3.  *
  4.  */
  5. #include <functions.h>        /* to hell with Lattice */
  6. #include <exec/types.h>
  7. #include <exec/nodes.h>
  8. #include <exec/lists.h>
  9. #include <exec/memory.h>
  10. #include <libraries/dos.h>
  11. #include <libraries/dosextens.h>
  12. #include <libraries/filehandler.h>
  13.  
  14. #include <exec/interrupts.h>
  15. #include <exec/ports.h>
  16. #include <exec/libraries.h>
  17. #include <exec/io.h>
  18. #include <exec/tasks.h>
  19. #include <exec/execbase.h>
  20. #include <exec/devices.h>
  21. #include <devices/trackdisk.h>
  22.  
  23. #define    TD_READ    CMD_READ
  24.  
  25. extern struct DosLibrary *DOSBase;    /* DOS Library base pointer */
  26.  
  27. SHORT error;
  28. struct MsgPort *read_port;
  29. struct IOExtTD *read_req;
  30.  
  31. char *device_name;
  32.  
  33. ULONG    unit;        /* unit number                    */
  34. ULONG    flags;        /* file system flags                */
  35. ULONG    capacity;    /* total sectors per unit (calculated)        */
  36. ULONG    bcapacity;    /* unit's capacity in bytes (calculated)    */
  37. ULONG    tblsize;    /* table size: standard value is 11        */
  38. ULONG    sizblk;        /* blocksize in longwords; standard is 128    */
  39. ULONG    secorg;        /* secorg: not used, must be 0            */
  40. ULONG    numheads;    /* number of heads/cylinder, drive specific    */
  41. ULONG    secblk;        /* number of sectors/block, not used, must be 1    */
  42. ULONG    blkstrk;    /* blocks per track, drive specific        */
  43. ULONG    reserved;    /* sectors reserved at start, usually 2        */
  44. ULONG    prefac;        /* prefac, not used, must be 0            */
  45. ULONG    interleave;    /* interleave, usually 0            */
  46. ULONG    locyl;        /* low cylinder number, typically 0        */
  47. ULONG    hicyl;        /* high cylinder number, drive specific        */
  48. ULONG    numbufs;    /* starting number of buffers, typically 5    */
  49. ULONG    membuftype;    /* memory buffer type, default is 3, and    */
  50.             /*    hard disks want 0                */
  51.  
  52. extern struct MsgPort   *CreatePort();
  53. extern struct IORequest *CreateExtIO();
  54.  
  55. main(argc, argv)
  56.    int argc;
  57.    char *argv[];
  58. {
  59.    char buf[128];
  60.     
  61.    read_port = CreatePort(0, 0);
  62.    if (read_port == NULL)
  63.       quit(100);
  64.  
  65.    read_req =(struct IOExtTD *)CreateExtIO(read_port,sizeof(struct IOExtTD));
  66.    if (read_req == NULL)
  67.       quit(200);
  68.  
  69.    strcpy(buf, "df1");
  70.    if (argc > 1)
  71.       strcpy(buf, argv[1]);
  72.    if (buf[3] == ':')
  73.       buf[3] = 0;
  74.    if (buf[4] == ':')
  75.       buf[4] = 0;
  76.  
  77.    init_device (buf);
  78.  
  79.    error = OpenDevice (device_name, unit, read_req, 0);
  80.    if (error) {
  81.       printf("OpenDevice return was: %lx\n", error);
  82.       quit(1);
  83.    }
  84.  
  85. printf("/* Table size = %ld, sectors/block = %ld\n", tblsize, secblk);
  86. printf(" * Size of a block = %ld longwords, %ld bytes\n", sizblk, sizblk*4L);
  87. printf(" * Formatted capacity = %ld blocks, %ld bytes, %ldK, %ld.%1ldM\n",
  88.                    capacity,
  89.                    bcapacity,
  90.                    bcapacity / 1024L,
  91.                    bcapacity / 1048576L,
  92.                    (bcapacity % 1048576L) / 104857L);
  93. printf(" */\n%s:       Device = %s\n", buf, device_name);
  94. printf("           Unit = %ld\n", unit);
  95. printf("           Flags = %ld\n", flags);
  96. printf("           Surfaces = %ld\n", numheads);
  97. printf("           BlocksPerTrack = %ld\n", blkstrk);
  98. printf("           Reserved = %ld\n", reserved);
  99. printf("           Interleave = %ld\n", interleave);
  100. printf("           LowCyl = %ld ; HighCyl = %ld\n", locyl, hicyl);
  101. printf("           Buffers = %ld\n", numbufs);
  102. if (12 == tblsize)
  103. printf("           BufMemType = %ld /* 3 = chip, 0 = fast */\n", membuftype);
  104. else
  105. printf("           BufMemType = 0 /* table short; 3 = chip, 0 = fast */\n");
  106. printf("#\n");
  107.  
  108.    MotorOff();
  109.    CloseDevice(read_req);
  110.    quit(0);
  111. }
  112.  
  113.  
  114. MotorOff()
  115. {
  116.    read_req->iotd_Req.io_Length = 0;
  117.    read_req->iotd_Req.io_Command = TD_MOTOR;
  118.    DoIO(read_req);
  119.    return(0);
  120. }
  121.  
  122. quit(return_code)
  123. {
  124.    if (read_req)
  125.       DeleteExtIO(read_req);
  126.    if (read_port)
  127.       DeletePort(read_port);
  128.    printf("\233 p");        /* turn cursor back on */
  129.    exit(return_code);
  130. }
  131.  
  132.  
  133. init_device (name)
  134.    register char *name;
  135. {
  136.    struct          RootNode          *root_node;
  137.    struct          DosInfo           *info_node;
  138.    register struct DeviceNode        *device_node;
  139.    struct          FileSysStartupMsg *startup_msg;
  140.    ULONG                             *envptr;
  141.  
  142.  
  143.    root_node = (struct RootNode *) DOSBase->dl_Root;
  144.    info_node = (struct DosInfo *) BADDR (root_node->rn_Info);
  145.    device_node = (struct DeviceNode *) BADDR (info_node->di_DevInfo);
  146.    while (device_node) {
  147.       if (device_node->dn_Type == DLT_DEVICE ) {
  148.          if (match (name, BADDR (device_node->dn_Name) + 1) == 0)
  149.                 break;
  150.       }
  151.       device_node = (struct DeviceNode *) BADDR (device_node->dn_Next);
  152.    }
  153.    if (device_node == 0) {
  154.       printf ("Device %s: not found\n", name);
  155.       quit (1);
  156.    }
  157.    startup_msg = (struct FileSysStartupMsg *) 
  158.                                   BADDR (device_node->dn_Startup);
  159.    unit        =                  startup_msg->fssm_Unit; /* unit number */
  160.    flags       =                  startup_msg->fssm_Flags;
  161.    device_name = (char *) BADDR  (startup_msg->fssm_Device) + 1;
  162.    envptr      = (ULONG *) BADDR (startup_msg->fssm_Environ);
  163.    tblsize     = envptr[DE_TABLESIZE];
  164.    sizblk      = envptr[DE_SIZEBLOCK];
  165.    secorg      = envptr[DE_SECORG];
  166.    numheads    = envptr[DE_NUMHEADS];
  167.    secblk      = envptr[DE_SECSPERBLK];
  168.    blkstrk     = envptr[DE_BLKSPERTRACK];   /* numsects */
  169.    reserved    = envptr[DE_RESERVEDBLKS];
  170.    prefac      = envptr[DE_PREFAC];
  171.    interleave  = envptr[DE_INTERLEAVE];
  172.    locyl       = envptr[DE_LOWCYL];
  173.    hicyl       = envptr[DE_UPPERCYL];
  174.    numbufs     = envptr[DE_NUMBUFFERS];
  175.    membuftype  = envptr[DE_MEMBUFTYPE];
  176.  
  177.    capacity    = (hicyl - locyl + 1L) * blkstrk * numheads;
  178.    bcapacity   = capacity * sizblk * 4L;
  179. }
  180.  
  181. match (s1, s2)
  182.    register char *s1, *s2;
  183. {
  184.    register char c;
  185.    while ((c = toupper (*s1++)) == toupper (*s2++))
  186.       if (c == 0)
  187.          return (0);
  188.    return (1);
  189. }
  190.